#pragma once
#include"hash.h"

using namespace std;

template<class K, class V, class Hash = HashFunc<K>>
class unordered_map
{
	struct KeyOfData
	{
		const K operator()(const pair<const K, V>& kv)
		{
			return kv.first;
		}
	};
	typedef HashTable<K, pair<const K, V>, KeyOfData, Hash> HT;
	typedef HashNode<pair<const K, V>> Node;
public:
	typedef typename HT::Iterator iterator;
	typedef typename HT::ConstIterator const_iterator;

	iterator begin()
	{
		return _ht.Begin();
	}
	
	const_iterator begin() const
	{
		return _ht.Begin();
	}

	iterator end()
	{
		return _ht.End();
	}

	const_iterator end() const
	{
		return _ht.End();
	}

	pair<iterator, bool> Insert(const pair<const K, V>& kv)
	{
		return _ht.Insert(kv);
	}

	iterator Find(const K& key)
	{
		return _ht.Find(key);
	}

	bool Erase(const K& key)
	{
		return _ht.Erase(key);
	}

	int Size()
	{
		return _ht.Size();
	}

	V& operator[](const K& key)
	{
		pair<iterator, bool> tmp1 = Insert({ key, V() });
		return tmp1.first->second;
	}

private:
	HT _ht;
};
